<?php if($action=='view'):?>
    <form method="post" action="<?php echo $this->baseurl("/managestore/orders/view/{$oderdata['id']}") ?>">
    <?php App::Helper('Toolbar')->setTitle("#{$oderdata['id']} Order Information")->setBtnSave()->setBtnBack()->Render(array('code'=>'appstore_order_view_top'));?>
    <?php  if(!empty($oderdata)){?>
		<?php
            echo App::Helper("Html")->getTag("h3",array("class"=>"first"),"Price and Status");
            $Grid = App::Module('DataGrid')->setDisplay('FormListing')
				->addRow("Order Id",$oderdata['id'])
				->addRow("Qty",$oderdata['qty'])
				->addRow("Total Cost",App::Helper('Config')->setting('currency','USD') . number_format($oderdata['totalcost'],2))
				->addRow("Order Date",App::Helper('Date')->dateFormated($oderdata['orderdate']))
				->addRow("Payment Method","{$oderdata['paymenttype']}")
				->addRow("Payment Status",App::Helper('Html')->selectTag("data[Order][paymentstatus]",App::Component('Appstore')->Helper('Data')->getPaymentStatusList(),"{$oderdata['paymentstatus']}",null,array("off_blank"=>"Yes")))
				->addRow("Delivery Status",App::Helper('Html')->selectTag("data[Order][deliverystatus]",App::Component('Appstore')->Helper('Data')->getDeliveryStatusList(),"{$oderdata['deliverystatus']}",null,array("off_blank"=>"Yes")))
				->Render();
        ?>		
        <table width="100%">
			<tr>
                <td width="50%" valign="top" style="padding:5px;">
					<h3 ><?php echo $this->__("Billing Address");?></h3>
					<?php if($oderdata['billingaddress'] != ''):?>
						<?php
						$shippingaddress = unserialize($oderdata['billingaddress']);
						$Grid = App::Module('DataGrid')->clear()
							->setDisplay('FormListing')
							->addRow("Name","{$shippingaddress['fname']} {$shippingaddress['lname']}")
							->addRow("Address Line 1","{$shippingaddress['address_line_1']}")
							->addRow("Address Line 2","{$shippingaddress['address_line_2']}")
							->addRow("City","{$shippingaddress['city']}")
							->addRow("State/Province","{$shippingaddress['state']}")
							->addRow("Postal/Zip Code","{$shippingaddress['zipcode']}")
							->addRow("Country",App::Helper('Utility')->CountryCodeToName($shippingaddress['country']))
							->addRow("Email",$shippingaddress['email'])
							->addRow("Phone No",$shippingaddress['phoneno'])
							->Render();
						?>
					<?php else:?>
						<div class="box">
						<?php 
							echo $this->callElement(
								'default/tools/message', 
								array(
									'caption' =>'Message',
									'type' => 'message', 
									'message' => 'Billing Addres is not defined.'
								)
							);
						?>
						</div>
					<?php endif;?>
                </td>
                <td style="padding:5px;" valign="top">
					<h3 ><?php echo $this->__("Shipping Address");?></h3>
					<?php if($oderdata['shippingaddress'] != ''):?>
						<?php
						$shippingaddress = unserialize($oderdata['shippingaddress']);
						$Grid = App::Module('DataGrid')->clear()
							->setDisplay('FormListing')
							->addRow("Name","{$shippingaddress['fname']} {$shippingaddress['lname']}")
							->addRow("Address Line 1","{$shippingaddress['address_line_1']}")
							->addRow("Address Line 2","{$shippingaddress['address_line_2']}")
							->addRow("City","{$shippingaddress['city']}")
							->addRow("State/Province","{$shippingaddress['state']}")
							->addRow("Postal/Zip Code","{$shippingaddress['zipcode']}")
							->addRow("Country",App::Helper('Utility')->CountryCodeToName($shippingaddress['country']))
							->addRow("Email",$shippingaddress['email'])
							->addRow("Phone No",$shippingaddress['phoneno'])
							->Render();
						?>
					<?php else:?>
						<div class="box">
						<?php 
							echo $this->callElement(
								'default/tools/message', 
								array(
									'caption' =>'Message',
									'type' => 'message', 
									'message' => 'Shipping method is not applicable.'
								)
							);
						?>
						</div>
					<?php endif;?>
                </td>
            </tr>
            <tr>
        </table>			
		<?php
			echo App::Helper("Html")->getTag("h3","Items Information");
			$items = App::Model('Item')->findAllByOrderId($oderdata['id']);

			$Grid = App::Module('DataGrid')->clear();
			$QTY = 0;
			$TOTAL = 0;
			foreach($items['data'] as $item)
			{
				$attributeStr = App::Component('appStore')->Helper('Common')->getItemAttributes($item,'html');
				
				$Grid->addRow(
					$item['id'],
					$item['title'],
					$item['qty'],
					$attributeStr,
					App::Config()->setting('currency','USD') . number_format($item['unitprice'],2),
					App::Config()->setting('currency','USD') . number_format($item['totalprice'],2)
				);
				
				$QTY   += $item['qty'];
				$TOTAL += $item['totalprice'];
			}
			
			$Grid->setHeader(Array("ID","Title","Qty","Attribute","Unit Price","Total"))
				 ->setFooter(Array("","","{$QTY}(Total Qty)","","",App::Config()->setting('currency','USD') . number_format($TOTAL,2)))
				 ->Render();			
			
			
			echo App::Helper("Html")->getTag("h3",array("style"=>"color:#FFF;background-color:green"),"Order Total Cost " . App::Config()->setting('currency','USD') .  $oderdata['totalcost']);
			$Grid = App::Module('DataGrid')->clear()
				->setDisplay('FormListing')
				->addRow("Item Total", App::Config()->setting('currency','USD') . number_format($TOTAL,2))
				->addRow("Shipping Cost", App::Config()->setting('currency','USD') . number_format($oderdata['shippingcost'],2))	
				->addRow("Discount Amount", App::Config()->setting('currency','USD') . number_format($oderdata['discount'],2))
				->addRow("Total Cost", App::Config()->setting('currency','USD') . number_format($oderdata['totalcost'],2))	
				->Render();	 
		?>
    <?php
        }
        else
        {
            echo $this->callElement('default/tools/message', array('caption' =>'Message','type' => 'error', 'message' => 'No Data found for Account'));
        }
        App::Helper('Toolbar')->setBtnSave()->setBtnBack()->Render(array('code'=>'appstore_order_top'));
    ?>
    </form>
<?php else:?>
    <?php
    App::Helper('Toolbar')->setTitle("Manage Orders")->setBtnDelete(array("id"=>"{'mode':'order'}"))->setBtnBack()->Render(array('code'=>'appstore_order_top'));
        if(!empty($oderdata['data']))
        {
            $Grid = App::Module('DataGrid');
            $Grid->setHeader(array($this->get_tag('input',array('type'=>'checkbox','id'=>'checkall','class'=>"checkall")),'ID', 'Item Qty','Total Cost','Date','Payment Method','Delivery Status','Payment Status','Options'));
            $Grid->setFooter($oderdata['paging_str']);
            foreach($oderdata['data'] as $key=>$val){
                $shippingaddress = unserialize($val['shippingaddress']);

                $Grid->addRow(
                    $this->get_tag('input',array('type'=>'checkbox','value'=>"{$val['id']}","class"=>"checkrow")),
                    $val['id'],
                    $val['qty'],
                    number_format($val['totalcost'],2), 
                    App::Helper('Date')->dateFormated($val['orderdate']),
                    $val['paymenttype'],
                    $val['deliverystatus'],
                    $val['paymentstatus'],
                    App::load("Helper/Html")->linkTag($this->baseurl('/managestore/orders/view/' . $val['id']),App::load("Helper/Html")->imgTag($this->baseurl('/images/admin/view.gif'),NULL,array('title'=>'Edit ','alt' => 'View',"class"=>"icon")),array("title"=>"Edit user information"))
                    . App::load("Helper/Html")->linkTag("javascript:void(0)",App::load("Helper/Html")->imgTag($this->baseurl('/images/admin/remove.gif'),NULL,array('title'=>'Delete','alt'=>'Delete')),array('id'=>'Order_' . $val['id'],'class'=>'link_delete icon', 'title'=>'Order_' . $val['id']))
                    );
            }
            $Grid->Render();
        }
        else
        {
            echo $this->callElement('default/tools/message', array('caption' =>'Message','type' => 'warning', 'message' => 'No Data found'));
        }
        App::Helper('Toolbar')->setBtnBack()->Render(array('code'=>'appstore_order_bottom'));
    ?>
<?php endif;?>